<!--  -->
<template>
  <div>
    <div class="song-list">
      <div class="play"><span>播放全部</span><span>({{data.length}})</span> </div>
      <div v-for="(item, index) in data" class="list">
        <div class="left" @click="imgClick(index)"><img :src="item.imgUrl" alt="" /></div>
        <div class="center" @click="centerClick(index)">
          <span>{{ item.name }}</span>
          <span>{{ item.artistName | combine(item.albumName) }}</span>
        </div>
        <div class="right">
          <span>···</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>


export default {
  name: 'SongList',
  props: {
    data: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  components: {
    
  },
  methods: {
    imgClick(index) {
      this.$store.commit('setData',{
        songList: this.data,
        index,
      })
    },
    centerClick(index) {
      this.$store.commit('setData',{
        songList: this.data,
        index,
        })
      this.$store.commit('fullScreen')
    }
  },
  filters: {
    combine(artistName, albumName) {
      if (artistName.length == 1) {
        return artistName[0].name + " - " + albumName;
      } else {
        let name = [];
        for (let item of artistName) {
          name.push(item.name);
        }
        return name.join("/") + " - " + albumName;
      }
    },
  },
};
</script>
<style lang='scss' scoped>
.song-list {
  .play {
    span:nth-child(2) {
      color: $color-text-l;
      margin-left: 5px;
    }
  }
  .list {
    display: flex;
    justify-content: space-between;
    height: 50px;
    margin-top: 10px;
    font-size: $font-size-small;
    .left {
      width: 50px;
      height: 50px;
      img {
        width: 50px;
        height: 50px;
        border-radius: 10px;
      }
    }
    .center {
      flex: 1;
      width: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      margin: 3px 10px;
      overflow: hidden;
      span {
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      span:nth-child(1) {
        font-size: $font-size-medium-x;
      }
    }
    .right {
      width: 30px;
      text-align: center;
      line-height: 50px;
      font-size: $font-size-large-x;
    }
  }
}
</style>